// pages/info/recharge/recharge.js
var MD5 = require('../../../utils/util.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  
  /* 微信支付 */
  requestPayments: function (e) {
    var gid = e.currentTarget.dataset.gid;
    let that = this;
    var smsInfo = wx.getStorageSync('smsInfo');
    var openId = wx.getStorageSync('openId');
    wx.showLoading({
      title: '订单提交中',
    })
    wx.login({
      success: function (res) {
        if (res.code) {
          //发起网络请求
          wx.request({
            url: app.globalData.smsbaoApi + '/batch/sapi/getOpenId',
            method: 'post',
            data: {
              code: res.code
            },
            success: function (res) {
              wx.request({
                url: app.globalData.smsbaoApi + "/mm/wap/tool_order",
                method: 'post',
                data: {
                  uid: smsInfo.userId,
                  gid: gid,
                  name: smsInfo.username,
                  openId: res.data.data.openId,
                  auth: smsInfo.token,
                  ptype: 'wechat'
                },
                success: function (res) {
                  that.pay(res.data)
                }
              })
            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    });
  
  },
  /* 支付   */
  pay: function (param) {
    wx.hideLoading()
    wx.requestPayment({
      timeStamp: param.timeStamp,
      nonceStr: param.nonceStr,
      package: param.package,
      signType: param.signType,
      paySign: param.paySign,
      success: function (res) {
        wx.redirectTo({
          url: '/pages/info/bill/bill'
        })
      }
    })
  }

})